var over = 0;
var id = 0;

var thisPage = {
    // 初始化页面
    OnPageLoad: function () {
        thisPage.PageInit();
    },
    GetFilters: function () {
        let _params = {};
        _params["HeaderId"] = parseInt(id);
        _params['CurrentUserId'] = parseInt(parent.$("#UserId").val());
        _params['WorkFlowId'] = parent.$("#WorkFlowId").val() === '' ? 0 : parseInt(parent.$("#WorkFlowId").val());
        _params['PageIndex'] = 1;
        _params['Limit'] = 500;
        _params['LimitPoLines'] = 10;   // 无用，纯粹是为了调用
        return JSON.stringify(_params);
    },
    PageInit: function () {
        $.ajax({
            type: "POST",
            url: window.basePath + "/inventory/stock_in/header/fetchByKey.html",
            timeout: 30 * 1000,
            data: thisPage.GetFilters(),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {
            }
        }).done(function (data) {
            let item = data.HeaderEntity;
            $("#StockInDate").text(item.stockInDate);
            $("#BillNo").text(item.billNo);
            //$("#PrintedDate").text(getCurrentDate());                 // 打印日期
            thisPage.BuildDataTable(data.LinesList);
        }).fail(function (data) {
            $('#loading').hide();
            ajaxError(data, 1);
        }).always(function () {
            $('#loading').hide();
        });
    },
    // html打印
    DoPreview: function () {
        window.print();
    },
    BuildDataTable(result){
        $('#tabData tbody').empty();
        // 得到数据列表
        result = result.DataList;
        if (result === null) {
            return false;
        }
        let content = '';
        for (let i = 0; i < result.length; i++) {
            content += '<tr>';
            content += '<td class="cell">' + formatNullData(result[i].styleNo) + '</td>';
            content += '<td class="cell">' + formatNullData(result[i].materialCode) + '</td>';
            content += '<td class="cell">' + formatNullData(result[i].materialName) + '</td>';
            content += '<td class="cell">' + formatNullData(result[i].materialColourName) + '</td>';        // 色名
            content += '<td class="cell">' + formatNullData(result[i].specification) + '</td>';             // 规格
            //content_02 += '<td style="text-align:center;">' + formatNullData(result[i].uomName) + '</td>';   // 单位
            content += '<td class="cell">' + formatNullData(result[i].receivedQuantity) + '</td>';          // 到货数
            //content_02 += '<td style="border-right:none;">' + result[i].stockInQuantity + '</td>';           // 实到数量(入库数=结算对账数)
            content += '</tr>';
            
            $("#tabData tbody").append(content);
            content = '';
        }
    }
};

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    id = jQuery.url.param("id");
    thisPage.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
}
